package com.cloud.securityoauth2client1.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("info")
public class ClientController {



    @GetMapping("getCurrentUser")
    public Object getCurrentUser(Authentication authentication) {
        return authentication;
    }


    @PostMapping("login")
    public Object login(Authentication authentication) {
        return "hello login 9502";
    }

    @PreAuthorize("hasAuthority('admin')")
    @GetMapping("auth/admin")
    public Object adminAuth() {
        return "Has admin auth! 9502";
    }


    @PreAuthorize("hasAuthority('client')")
    @GetMapping("auth/client")
    public Object clientAuth() {
        return "Has client auth! 9502";
    }

}
